from dataclasses import dataclass


@dataclass
class Person:
    name: str
    age: int
    # def __init__(self, name: str, age: int):
    #     print("开始进行初始化")
    def __post_init__(self):
        print(f"初始化后处理：{self.name} 已创建")


# 创建实例时，__post_init__ 会自动触发
p = Person("Alice", 30)
print(p.age)
print(p.__repr__)


from dataclasses import dataclass, field

@dataclass
class GoodExample:
    items: dict = field(default_factory=dict)  # 每次创建新列表

a = GoodExample()
b = GoodExample()
a.items["a"] = 1
print(a.items)  # 输出: []（正确隔离）
print(b.items)  # 输出: []（正确隔离）

import re
print(re.search(r"\{\{[a-zA-Z_][a-zA-Z0-9_]*\}\}", "\n\n"))